﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TanashCMS.Business;
using NHibernate;
using System.IO;

public partial class manager_blog_Default : CMSManagementPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptBlogPosts.DataSource = WebPage.GetAllBlogPosts((int)Profile.GetPropertyValue("WebsiteID"));
            DataBind();
        }
    }
    protected void btnNewPost_Click(object sender, EventArgs e)
    {
        ISession session = Configuration.GetCurrentSession();
        ITransaction tx = session.BeginTransaction();

        int pageid = 0;
        WebPage newPage = new WebPage();
        newPage.Website = mWebsite;
        newPage.Title = "";
        newPage.State = CMSObjectState.Shallow;
        newPage.ObjectType = CMSObjectType.WebPage;
        newPage.PageType = WebPageType.Standard;
        newPage.IsBlogPost = true;
        newPage.MasterPage = "default";
        newPage.GUID = Guid.NewGuid().ToString();

        try
        {
            session.Save(newPage);

            mWebsite.NeedsPublish = true;
            session.SaveOrUpdate(mWebsite);
            CMSMasterPage.setPublishLinkVisibility(true);

            session.Flush();
            tx.Commit();
            pageid = newPage.ID;
            session.Disconnect();
        }
        catch (Exception ex)
        {
            tx.Rollback();
            session.Disconnect();
            ShowSystemFeedback(ex.Message);
            return;
        }
        Response.Redirect("../pages/Build.aspx?for=blog&id=" + pageid.ToString());

    }
}
